package com.xykj.enterprise.wechat.ext.api.externalcontact;

import com.xykj.enterprise.wechat.bean.ext.externalcontact.GetExternalContactBatchVo;
import com.xykj.enterprise.wechat.ext.service.customer.ExternalContactService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Function(description = "批量获取客户详情", parameters = {
        @Parameter(name = "access_token", type = Type.String, description = "access_token", required = true),

        @Parameter(name = "userid", type = Type.String, description = "企业成员的userid，字符串类型", required = true),
        @Parameter(name = "cursor", type = Type.String, description = "用于分页查询的游标，字符串类型，由上一次调用返回，首次调用可不填", required = false),
        @Parameter(name = "limit", type = Type.Integer, description = "返回的最大记录数，整型，最大值100，默认值50，超过最大值时取最大值", required = false),
})
@Component
public class GetExternalContactBatch implements Action {

    @Autowired
    ExternalContactService externalContactService;

    @Override
    public Response execute(Request request) throws Exception {

        GetExternalContactBatchVo rsp = externalContactService.getExternalContactBatch(
                request.getString("access_token"),
                request.getString("userid"),
                request.getString("cursor"),
                request.getInteger("limit")
        );

        if (rsp.getErrcode() != 0) {
            return Response.fail(rsp.getErrmsg());
        }
        return Response.success().put("data", rsp);
    }
}
